package com.ninong.ker.common.conf;
import java.util.Properties;

import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;

import com.alibaba.druid.util.DruidPasswordCallback;
import com.ninong.ker.common.tools.CmdAdminTools;
 
/**
 * 数据库回调密码解密
 * 
 * @author cmd
 *
 */
@Component
public class DbPasswordCallback extends DruidPasswordCallback {
 
	/**
	 * 
	 */
	private static final long serialVersionUID = -3289051285855077234L;

	@Override
	public void setProperties(Properties properties) {
		super.setProperties(properties);
		String password = properties.getProperty("password");
		if (StringUtils.isNotEmpty(password)) {
			try {
				//所以这里的代码是将密码进行解密
				String sourcePassword = CmdAdminTools.aesDncode(password);
				setPassword(sourcePassword.toCharArray());
			} catch (Exception e) {
				setPassword(password.toCharArray());
			}
		}
	}
}